home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LT_GetAttributes.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  10KB  |  493 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <stdarg.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24. LONG
  25. LT_GetAttributes(LayoutHandle *Handle,LONG ID,...)
  26. {
  27.     va_list VarArgs;
  28.     LONG    Result;
  29.  
  30.     va_start(VarArgs,ID);
  31.     Result = LT_GetAttributesA(Handle,ID,(struct TagItem *)VarArgs);
  32.     va_end(VarArgs);
  33.  
  34.     return(Result);
  35. }
  36.  
  37.  
  38. /*****************************************************************************/
  39.  
  40.  
  41. /****** gtlayout.library/LT_GetAttributesA ******************************************
  42. *
  43. *   NAME
  44. *    LT_GetAttributesA -- Inquire information on a gadget.
  45. *
  46. *   SYNOPSIS
  47. *    Value = LT_GetAttributesA(Handle,ID,Tags);
  48. *      D0                        A0   D0  A1
  49. *
  50. *    LONG LT_GetAttributesA(LayoutHandle *,LONG ID,struct TagItem *);
  51. *
  52. *    Value = LT_GetAttributes(Handle,ID,...);
  53. *
  54. *    LONG LT_GetAttributes(LayoutHandle *,LONG ID,...);
  55. *
  56. *   FUNCTION
  57. *    All objects created by the user interface layout code posess
  58. *    certain unique properties. The LT_GetAttributes() function will
  59. *    will inquire this information and return it. The implementation
  60. *    differs from gadtools.library/GT_GetGadgetAttrs in that you
  61. *    can inquire only a small subset of the object properties possible
  62. *    via the taglist passed in.
  63. *
  64. *   INPUTS
  65. *    Handle - Pointer to LayoutHandle structure.
  66. *
  67. *    ID - ID number of the object to inquire information about. This
  68. *        is the same value you passed via LA_ID to LT_New() when
  69. *        you created this object.
  70. *
  71. *    Tags - TagItem list to receive information about the object
  72. *        in question.
  73. *
  74. *
  75. *    LA_Left (LONG *) - Left edge of object.
  76. *
  77. *    LA_Top (LONG *) - Top edge of object.
  78. *
  79. *    LA_Width (LONG *) - Width of object.
  80. *
  81. *    LA_Height (LONG *) - Height of object.
  82. *
  83. *    LA_Chars (LONG *) - Width of object measured in character
  84. *        widths. (V9)
  85. *
  86. *    LA_Lines (LONG *) - Height of object measured in character
  87. *        heights. (V9)
  88. *
  89. *    LA_LabelLeft (LONG *) - Left edge of label text. (V9)
  90. *
  91. *    LA_LabelTop (LONG *) - Top edge of label text. (V9)
  92. *
  93. *    LABO_Object (Object *) - Returns a pointer to the BOOPSI object
  94. *        the BOOPSI_KIND object is based upon. (V10)
  95. *
  96. *            NOTE: Don't unlink the object or dispose of it or
  97. *                terrible things are bound to happen.
  98. *
  99. *    LAST_CursorPosition (LONG *) - Current position of the cursor
  100. *        in STRING_KIND and FRACTION_KIND objects. (V
  101. *
  102. *   RESULT
  103. *    The result depends on the object type:
  104. *
  105. *        VERTICAL_KIND:
  106. *        HORIZONTAL_KIND:
  107. *
  108. *            active page
  109. *
  110. *        SCROLLER_KIND:
  111. *
  112. *            current GTSC_Top value
  113. *
  114. *        TAPEDECK_KIND:
  115. *
  116. *            current LATD_Pressed value
  117. *
  118. *        LEVEL_KIND:
  119. *
  120. *            current LAVL_Level state
  121. *
  122. *        CHECKBOX_KIND:
  123. *
  124. *            current GTCB_Checked state
  125. *
  126. *        LISTVIEW_KIND:
  127. *
  128. *            current GTLV_Selected state
  129. *
  130. *        MX_KIND:
  131. *
  132. *            current GTMX_Active state
  133. *
  134. *        CYCLE_KIND:
  135. *
  136. *            current GTCY_Active state
  137. *
  138. *        POPUP_KIND:
  139. *
  140. *            current LAPU_Active state
  141. *
  142. *        TAB_KIND:
  143. *
  144. *            current LATB_Active state
  145. *
  146. *        PALETTE_KIND:
  147. *
  148. *            current GTPA_Color state
  149. *
  150. *        SLIDER_KIND:
  151. *
  152. *            current GTSL_Level state
  153. *
  154. *        GAUGE_KIND:
  155. *
  156. *            current LAGA_Percent state
  157. *
  158. *        STRING_KIND:
  159. *
  160. *            pointer to current string
  161. *
  162. *        PASSWORD_KIND:
  163. *
  164. *            pointer to current string
  165. *
  166. *        INTEGER_KIND:
  167. *
  168. *            number currently entered
  169. *
  170. *        BOOPSI_KIND:
  171. *
  172. *            whatever the object thinks is its
  173. *            current value
  174. *
  175. ******************************************************************************
  176. *
  177. */
  178.  
  179. LONG LIBENT
  180. LT_GetAttributesA(REG(a0) LayoutHandle *Handle,REG(d0) LONG ID,REG(a1) struct TagItem *TagList)
  181. {
  182.     if(Handle)
  183.     {
  184.         struct TagItem    *ThisTag;
  185.         ObjectNode        *Node = NULL;
  186.  
  187.         if(ThisTag = FindTagItem(LAPR_Gadget,TagList))
  188.             Node = ((struct Gadget *)ThisTag->ti_Data)->UserData;
  189.  
  190.         if(!Node)
  191.         {
  192.             if(ThisTag = FindTagItem(LAPR_Object,TagList))
  193.                 Node = (ObjectNode *)ThisTag->ti_Data;
  194.         }
  195.  
  196.         if(!Node)
  197.             Node = LTP_FindNode(Handle,ID);
  198.  
  199.         if(Node)
  200.         {
  201.             struct Gadget *Gadget = Node->Host;
  202.  
  203.             if(TagList)
  204.             {
  205.                 struct TagItem    *TagItem,
  206.                                 *TempPtr = TagList;
  207.                 LONG            *Value;
  208.  
  209.                 while(TagItem = NextTagItem(&TempPtr))
  210.                 {
  211.                     Value = (LONG *)TagItem->ti_Data;
  212.  
  213.                     switch(TagItem->ti_Tag)
  214.                     {
  215.                         case LA_Left:
  216.  
  217.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  218.                                 *Value = Node->Left + 4;
  219.                             else
  220.                                 *Value = Node->Left;
  221.  
  222.                             break;
  223.  
  224.                         case LA_Top:
  225.  
  226.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  227.                                 *Value = Node->Top + 2;
  228.                             else
  229.                                 *Value = Node->Top;
  230.  
  231.                             break;
  232.  
  233.                         case LA_Width:
  234.  
  235.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  236.                                 *Value = Node->Width - 8;
  237.                             else
  238.                                 *Value = Node->Width;
  239.  
  240.                             break;
  241.  
  242.                         case LA_Height:
  243.  
  244.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  245.                                 *Value = Node->Height - 4;
  246.                             else
  247.                                 *Value = Node->Height;
  248.  
  249.                             break;
  250.  
  251.                         case LAST_CursorPosition:
  252.  
  253.                             *Value = 0;
  254.  
  255.                             if(Node->Type == STRING_KIND || Node->Type == FRACTION_KIND)
  256.                             {
  257.                                 if(Gadget != NULL)
  258.                                 {
  259.                                     struct StringInfo *StringInfo = Gadget->SpecialInfo;
  260.  
  261.                                     *Value = StringInfo->BufferPos;
  262.                                 }
  263.                             }
  264.  
  265.                             break;
  266.  
  267.                         #ifdef DO_BOOPSI_KIND
  268.                         {
  269.                             case LABO_Object:
  270.  
  271.                                 if(Node->Type == BOOPSI_KIND)
  272.                                     *Value = (LONG)Node->Host;
  273.                                 else
  274.                                     *Value = NULL;
  275.  
  276.                                 break;
  277.                         }
  278.                         #endif    /* DO_BOOPSI_KIND */
  279.  
  280.                         case LA_Chars:
  281.  
  282.                             *Value = Node->Chars;
  283.                             break;
  284.  
  285.                         case LA_Lines:
  286.  
  287.                             *Value = Node->Lines;
  288.                             break;
  289.  
  290.                         case LA_LabelLeft:
  291.  
  292.                             switch(Node->LabelPlace)
  293.                             {
  294.                                 case PLACE_LEFT:
  295.  
  296.                                     *Value    = Node->Left - (INTERWIDTH + Node->LabelWidth);
  297.                                     break;
  298.  
  299.                                 case PLACE_RIGHT:
  300.  
  301.                                     *Value    = Node->Left + Node->Width + INTERWIDTH;
  302.                                     break;
  303.  
  304.                                 case PLACE_ABOVE:
  305.  
  306.                                     *Value    = Node->Left + (Node->Width - Node->LabelWidth) / 2;
  307.                                     break;
  308.  
  309.                                 case PLACE_BELOW:
  310.  
  311.                                     *Value    = Node->Left + (Node->Width - Node->LabelWidth) / 2;
  312.                                     break;
  313.  
  314.                                 case PLACE_IN:
  315.  
  316.                                     *Value    = Node->Left + (Node->Width - Node->LabelWidth) / 2;
  317.                                     break;
  318.                             }
  319.  
  320.                             break;
  321.  
  322.                         case LA_LabelTop:
  323.  
  324.                             switch(Node->LabelPlace)
  325.                             {
  326.                                 case PLACE_LEFT:
  327.  
  328.                                     *Value    = Node->Top + (Node->Height - Handle->GlyphHeight) / 2;
  329.                                     break;
  330.  
  331.                                 case PLACE_RIGHT:
  332.  
  333.                                     *Value    = Node->Top + (Node->Height - Handle->GlyphHeight) / 2;
  334.                                     break;
  335.  
  336.                                 case PLACE_ABOVE:
  337.  
  338.                                     *Value    = Node->Top - (Handle->GlyphHeight + INTERHEIGHT);
  339.                                     break;
  340.  
  341.                                 case PLACE_BELOW:
  342.  
  343.                                     *Value    = Node->Top + Node->Height + INTERHEIGHT;
  344.                                     break;
  345.  
  346.                                 case PLACE_IN:
  347.  
  348.                                     *Value    = Node->Top + (Node->Height - Handle->GlyphHeight) / 2;
  349.                                     break;
  350.                             }
  351.  
  352.                             break;
  353.                     }
  354.                 }
  355.             }
  356.  
  357.             switch(Node->Type)
  358.             {
  359. #ifdef DO_POPUP_KIND
  360.                 case POPUP_KIND:
  361. #endif    /* DO_POPUP_KIND */
  362. #ifdef DO_TAB_KIND
  363.                 case TAB_KIND:
  364. #endif    /* DO_TAB_KIND */
  365. #ifdef DO_GAUGE_KIND
  366.                 case GAUGE_KIND:
  367. #endif    /* DO_GAUGE_KIND */
  368. #ifdef DO_TAPEDECK_KIND
  369.                 case TAPEDECK_KIND:
  370. #endif    /* DO_TAPEDECK_KIND */
  371. #ifdef DO_LEVEL_KIND
  372.                 case LEVEL_KIND:
  373. #endif    /* DO_LEVEL_KIND */
  374.  
  375.                 case CHECKBOX_KIND:
  376.                 case LISTVIEW_KIND:
  377.                 case MX_KIND:
  378.                 case CYCLE_KIND:
  379.                 case PALETTE_KIND:
  380.                 case SLIDER_KIND:
  381.                 case SCROLLER_KIND:
  382.  
  383.                     return(Node->Current);
  384.  
  385.                 #ifdef DO_BOOPSI_KIND
  386.                 {
  387.                     case BOOPSI_KIND:
  388.                     {
  389.                         ULONG Storage;
  390.  
  391.                         if(Gadget && GetAttr(Node->Special.BOOPSI.TagCurrent,Gadget,&Storage))
  392.                             return((LONG)Storage);
  393.                         else
  394.                             return(NULL);
  395.                     }
  396.                 }
  397.                 #endif    /* DO_BOOPSI_KIND */
  398.  
  399.                 case VERTICAL_KIND:
  400.                 case HORIZONTAL_KIND:
  401.  
  402.                     return((LONG)Node->Special.Group.Ac